package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.PurchaseReceiptItem;
import com.ruoyi.business.service.IPurchaseReceiptItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进货单明细Controller
 * 
 * @author ruoyi
 * @date 2025-03-20
 */
@RestController
@RequestMapping("/business/item")
public class PurchaseReceiptItemController extends BaseController
{
    @Autowired
    private IPurchaseReceiptItemService purchaseReceiptItemService;

    /**
     * 查询进货单明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseReceiptItem purchaseReceiptItem)
    {
        startPage();
        List<PurchaseReceiptItem> list = purchaseReceiptItemService.selectPurchaseReceiptItemList(purchaseReceiptItem);
        return getDataTable(list);
    }

    /**
     * 导出进货单明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:export')")
    @Log(title = "进货单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseReceiptItem purchaseReceiptItem)
    {
        List<PurchaseReceiptItem> list = purchaseReceiptItemService.selectPurchaseReceiptItemList(purchaseReceiptItem);
        ExcelUtil<PurchaseReceiptItem> util = new ExcelUtil<PurchaseReceiptItem>(PurchaseReceiptItem.class);
        util.exportExcel(response, list, "进货单明细数据");
    }

    /**
     * 获取进货单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(purchaseReceiptItemService.selectPurchaseReceiptItemById(id));
    }

    /**
     * 新增进货单明细
     */
    @PreAuthorize("@ss.hasPermi('business:item:add')")
    @Log(title = "进货单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseReceiptItem purchaseReceiptItem)
    {
        return toAjax(purchaseReceiptItemService.insertPurchaseReceiptItem(purchaseReceiptItem));
    }

    /**
     * 修改进货单明细
     */
    @PreAuthorize("@ss.hasPermi('business:item:edit')")
    @Log(title = "进货单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseReceiptItem purchaseReceiptItem)
    {
        return toAjax(purchaseReceiptItemService.updatePurchaseReceiptItem(purchaseReceiptItem));
    }

    /**
     * 删除进货单明细
     */
    @PreAuthorize("@ss.hasPermi('business:item:remove')")
    @Log(title = "进货单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purchaseReceiptItemService.deletePurchaseReceiptItemByIds(ids));
    }
}
